package com.joinway.framework.core.meta

import groovy.json.JsonOutput

import org.junit.Assert
import org.junit.Test

class GroovyMetaClassTest {

	@Test public void test1(){
		def obj = DynaBeanFactory.getBean()
		Assert.assertEquals("lee", obj.name)	
		Assert.assertEquals("lee", obj.getName())
		String json = JsonOutput.toJson(obj)
		println json
		println JsonOutput.prettyPrint(JsonOutput.toJson(obj))
	}
	
	@Test public void test2(){
		GroovyBean bean = DynaBeanFactory.getGroovyBean()
		Assert.assertEquals("lee", bean.name)
		Assert.assertEquals("lee", bean.getName())
		println JsonOutput.prettyPrint(JsonOutput.toJson(bean))
		
		Assert.assertTrue(bean instanceof GroovyObject)
	}

	@Test public void test3(){
		Object bean = DynaBeanFactory.getJavaBean()
		Assert.assertEquals("lee", bean.name)
		Assert.assertEquals("lee", bean.getName())
		
		JavaBean jb = new JavaBean()
		Assert.assertFalse(jb instanceof GroovyObject)
	}

}
